package com.example.administrator.exkotlin.coroutine.viewModel

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.administrator.exkotlin.coroutine.net.ResponseData
import com.example.administrator.exkotlin.coroutine.net.RetrofitCreator
import kotlinx.coroutines.launch

/**
 * Author by lp,on 2021/8/24/024,17:00.
 */
class DataViewModel : ViewModel() {
    val liveData = MutableLiveData<ResponseData>()

    fun refreshData() {
        //默认在主线程
        viewModelScope.launch {
            //自动挂起
            val data = RetrofitCreator.speedService.getSpeedInfo()
            Log.i("DataViewModel",data.toString())
            liveData.value = data
        }

    }
}